package com.ruoyi.history.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.history.domain.AiChatHistory;
import com.ruoyi.history.service.IAiChatHistoryService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * ai对话历史信息Controller
 * 
 * @author ruoyi
 * @date 2025-04-24
 */
@RestController
@RequestMapping("/aihistory/history")
public class AiChatHistoryController extends BaseController
{
    @Autowired
    private IAiChatHistoryService aiChatHistoryService;

    /**
     * 查询ai对话历史信息列表
     */
    @PreAuthorize("@ss.hasPermi('aihistory:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(AiChatHistory aiChatHistory)
    {
        startPage();
        List<AiChatHistory> list = aiChatHistoryService.selectAiChatHistoryList(aiChatHistory);
        return getDataTable(list);
    }

    /**
     * 导出ai对话历史信息列表
     */
    @PreAuthorize("@ss.hasPermi('aihistory:history:export')")
    @Log(title = "ai对话历史信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiChatHistory aiChatHistory)
    {
        List<AiChatHistory> list = aiChatHistoryService.selectAiChatHistoryList(aiChatHistory);
        ExcelUtil<AiChatHistory> util = new ExcelUtil<AiChatHistory>(AiChatHistory.class);
        util.exportExcel(response, list, "ai对话历史信息数据");
    }

    /**
     * 获取ai对话历史信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('aihistory:history:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aiChatHistoryService.selectAiChatHistoryById(id));
    }

    /**
     * 新增ai对话历史信息
     */
    @PreAuthorize("@ss.hasPermi('aihistory:history:add')")
    @Log(title = "ai对话历史信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AiChatHistory aiChatHistory)
    {
        aiChatHistory.setUserId(SecurityUtils.getUserId());
        return toAjax(aiChatHistoryService.insertAiChatHistory(aiChatHistory));
    }

    /**
     * 修改ai对话历史信息
     */
    @PreAuthorize("@ss.hasPermi('aihistory:history:edit')")
    @Log(title = "ai对话历史信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AiChatHistory aiChatHistory)
    {
        return toAjax(aiChatHistoryService.updateAiChatHistory(aiChatHistory));
    }

    /**
     * 删除ai对话历史信息
     */
    @PreAuthorize("@ss.hasPermi('aihistory:history:remove')")
    @Log(title = "ai对话历史信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aiChatHistoryService.deleteAiChatHistoryByIds(ids));
    }
}
